<template>
<div>
	<Card>
		<p slot="title">企业信息</p>
		<div style="max-width:500px;">
			<Form :ref="formRef" :model="model" :label-width="100">
				<FormItem label="网站Logo" prop="logo">
					<picture-single v-model="model" prop="logo" :height="50" :width="146" :showTip=false :disabled="!isEditing"></picture-single>
				</FormItem>
				<FormItem label="网站名称" prop="name" required>
					<Input v-model="model.name" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="网站关键字" prop="keyword">
					<Input v-model="model.keyword" type="textarea" :rows="3" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="网站描述" prop="description">
					<Input v-model="model.description" type="textarea" :rows="3" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="版权号" prop="copyright">
					<Input v-model="model.copyright" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="版权时效" prop="copyrightTimeLimit">
					<Input v-model="model.copyrightTimeLimit" :disabled="!isEditing" />
				</FormItem>
				<FormItem>
					<Button v-if="isEditing" type="primary" @click="handleSave" mgr2>保存修改</Button>
					<Button v-if="isEditing" @click="handleCancel">取消</Button>
					<Button v-if="!isEditing" type="primary" @click="isEditing=true">编辑</Button>
				</FormItem>
			</Form>
		</div>
	</Card>
</div>
</template>

<script lang="ts">
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';
import AbpBase from '../../lib/abpbase'
import PictureSingle from '@common/components/picture-single.vue'

@Component({
	components: { PictureSingle }
})
export default class ColumnArticleManager extends AbpBase{
	isEditing:boolean = false;
	showModal:boolean=false;
	formRef:string = this.getRandomRef('friendlylink-form')
	model:any = this.getDefaultModel()

	getDefaultModel() {
		return {
			logo: "",
			name: "",
			keyword: "",
			description: "",
			copyright: "",
			copyrightTimeLimit: ""
		}
	}
	async handleCancel() {
		await this.handleGetData();
		this.isEditing = false;
	}
	async handleSave() {
		(this.$refs[this.formRef] as any).validate( async (valid) => {
			if(valid) {
				var response = await this.post('WebsiteInfo/SetWebsiteInfo', this.model);
				if(response.success) {
					this.isEditing = false;
				}
			}
		});
	}
	async handleGetData() {
		var response = await this.get('WebsiteInfo/GetWebsiteInfo');
		if(response.success) {
			this.model = response.result;
		}
	}
	async created() {
		await this.handleGetData();
	}
}
</script>